package com.syni.mdd.sjb.common.datatreaure.controller.api;

import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.DxshAppIndustry;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.sjb.common.component.utils.feign.service.mdd.sjb.common.datatreasure.DxshApiIndustryRestService;
import com.syni.mdd.sjb.common.datatreaure.controller.protect.dataTreasure.business.BankBusinessController;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultCode;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultMsg;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.industry.GetAllIndustryVo;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppIndustryChooseService;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppIndustryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/apiAppIndustry")
public class DxshApiIndustryRestApi implements DxshApiIndustryRestService {

    @Autowired
    DxshAppIndustryService dxshAppIndustryService;

    @Autowired
    DxshAppIndustryChooseService dxshAppIndustryChooseService;


    @GetMapping("/getAllIndustry")
    @ApiOperation(value = "获取所有行业")
    public RpcResponseVo getAllIndustry(){
        GetAllIndustryVo getAllIndustryVo = new GetAllIndustryVo();
        Map<String,Object> resultMap = dxshAppIndustryService.getAllIndustry(getAllIndustryVo);
        if(ResultMapHelper.isSuccess(resultMap)){
            return RpcResponseVo.success(resultMap.get("data"),ResultMsg.MSG_GET_SUCCESS);
        }
        return RpcResponseVo.result(ResultCode.CODE_ERROR_100,ResultMsg.HAND_FAIL);
    }

    @Override
    public RpcResponseVo getBusinessTypeByChooseIndustry(Integer userId) {
        Set<String> typeNames = new HashSet<>();
        DxshAppIndustry dxshAppIndustry = dxshAppIndustryChooseService.getUserChooseInIndustry(userId);
        if(dxshAppIndustry != null){
            if(BankBusinessController.typeIndustryMap.containsKey(dxshAppIndustry.getIndustryName())){
                typeNames.addAll(BankBusinessController.typeIndustryMap.get(dxshAppIndustry.getIndustryName()));
            }
        }
        return RpcResponseVo.success(typeNames,ResultMsg.MSG_GET_SUCCESS);
    }

    @GetMapping("/getUserChooseIndustry")
    @ApiOperation(value = "获取用户选择行业")
    public Map<String,Object> getUserChooseIndustry(@RequestParam("userId") Integer userId){
        DxshAppIndustry dxshAppIndustry = dxshAppIndustryChooseService.getUserChooseInIndustry(userId);
        if(dxshAppIndustry != null){
            return ResultMapHelper.success(dxshAppIndustry);
        }
        return ResultMapHelper.result(ResultCode.CODE_ERROR_100,ResultMsg.HAND_FAIL);
    }
}
